<template>
  <div class="app-container">
    <!-- <div class="topBox">
      <div class="circle-stat"><div>请假人数</div> <div>{{todayLeaveTotal}}</div> </div>
    </div> -->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="请假时间">
        <el-date-picker
          v-model="dateRange"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table border stripe :header-cell-style="rowClass" v-loading="loading" :data="leavesList" >
      <el-table-column :resizable="false" label="序号" align="center"
        type="index" width="100">
      </el-table-column>
      <el-table-column :resizable="false" label="学生姓名" align="center" prop="studentsName" />
      <el-table-column :resizable="false" label="年级" align="center" prop="gradesName" />
      <el-table-column :resizable="false" label="班级" align="center" prop="className" />
<!--      <el-table-column :resizable="false" label="请假次数" align="center" prop="leaveTimes" />-->
      <el-table-column :resizable="false" label="开始时间" align="center" prop="beginDate">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.beginDate)}}</span>
        </template>
      </el-table-column>
      <el-table-column :resizable="false" label="结束时间" align="center" prop="endingDate">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.endingDate) }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getLeaveNumber"
    />
  </div>
</template>

<script>
import { listLeaves, getLeaves, delLeaves, addLeaves, updateLeaves, getLeavetotal } from "@/api/leaveSystem/leaveStatistics";
export default {
  name: "Leaves",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 请假总人数
      todayLeaveTotal: 0,
      //日期范围
      dateRange:[],
      // 请假表格数据
      leavesList: [],
      index:1,
      // 弹出层标题
      title: "",
      //请假审批是否显示弹出层
      leaveRecordOpen:false,
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        beginDate:null,
        className:null,
        endingDate:null,
        gradesName:null,
        leaveTimes:null,
        schoolId:null,
        studentsName:null,
        totalSchoolAbsences:null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        studentId: [
          { required: true, message: "学生ID不能为空", trigger: "blur" }
        ],
        parentId: [
          { required: true, message: "提交请假的id不能为空", trigger: "blur" }
        ],
        schoolId: [
          { required: true, message: "学校ID不能为空", trigger: "blur" }
        ],
        reason: [
          { required: true, message: "请假原因不能为空", trigger: "blur" }
        ],
        startTime: [
          { required: true, message: "开始时间不能为空", trigger: "blur" }
        ],
        endTime: [
          { required: true, message: "结束时间不能为空", trigger: "blur" }
        ],
        status: [
          { required: true, message: "状态：0=待审批, 1=审批通过, 2=审批拒绝不能为空", trigger: "change" }
        ],
        schoolComment:[
        { required: true, message: "意见不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {

    this.getLeaveNumber();
    // this.getList();
  },
  methods: {
    //设置table标题样式
    rowClass ({ row, rowIndex }) {
      return 'font-size: 15px; background-color: #FAFAFA;'
    },
    //获取当前时间
    // getDates(){
    //   let currentDate = new Date();
    //   let year = currentDate.getFullYear();
    //   let month = currentDate.getMonth() + 1;
    //   let day = currentDate.getDate();
    //   month = month < 10 ? '0' + month : month;
    //   day = day < 10 ? '0' + day : day;
    //   this.queryParams.beginDate=year + '-' + month + '-' + day;
    //   this.queryParams.endingDate=year + '-' + month + '-' + day;
    // },
    // 查询今天请假人数
    getLeaveNumber(){
      this.loading = true;
      if(this.dateRange.length!=0){
        this.queryParams.beginDate=this.dateRange[0];
        this.queryParams.endingDate=this.dateRange[1];
      }else if(this.dateRange.length==0){
        // this.getDates();
      }
      getLeavetotal(this.queryParams).then(response=>{
        this.leavesList = []
        this.loading = false;
        this.total=response.total
        if(response.rows.length==0)return
        // console.log("response.data[0]=",response.data)
        this.todayLeaveTotal=response.total
        this.leavesList = response.rows
      })
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        beginDate:null,
        className:null,
        endingDate:null,
        gradesName:null,
        leaveTimes:null,
        schoolId:null,
        studentsName:null,
        totalSchoolAbsences:null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getLeaveNumber()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.beginDate=null,
      this.queryParams.endingDate=null,
      this.dateRange=[];
      this.todayLeaveTotal=0
      this.resetForm("queryForm");
      this.handleQuery();
    }
  }
};
</script>
<style scoped lang="scss">
.topBox{
  height: 150px;
  display: flex;
  align-items: center;
  .circle-stat {
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: center;
    width: 120px;
    height: 120px;
    text-align: center;
    border-radius: 50%;
    background: linear-gradient(45deg, #ff9966, #ff5e62); /* 渐变背景 */
    color: white; /* 文本颜色 */
    font-size: 20px; /* 字体大小 */
    font-weight: bold; /* 字体加粗 */
    margin-right: 30px; /* 右边距 */
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.3); /* 阴影效果 */
  }

  .circle-stat::before {
    content: "";
    position: absolute;
    top: -10px;
    left: -10px;
    right: -10px;
    bottom: -10px;
    border-radius: 50%;
    background: inherit;
    opacity: 0.3;
    z-index: -1;
  }
}

</style>
